package com.dc.bobaoge.project.v2.to.v3.business.core.util;

import com.dc.bobaoge.common.em.UpdateAuthenticationInfoEnum;
import com.dc.bobaoge.project.base.core.old.entity.OldCoreCerCompany;
import com.dc.bobaoge.project.base.core.old.entity.OldCoreCerMessage;
import com.dc.bobaoge.project.base.core.old.entity.OldCoreCerPerson;
import com.own.business.sync.trigger.base.entity.SyncTrigger;
import org.apache.commons.lang3.StringUtils;

/**
 * CerMessageUtil
 *
 * @author chenxueli
 * @date 2024-01-29 09:28:00
 */
public class CerMessageUtil {

    /**
     * 计算认证信息的修改
     *
     * @param newItem   旧的认证信息
     * @param oldItem   新的认证信息
     * @param newPerson 旧的认证信息
     * @param oldPerson 新的认证信息
     * @return 修改的内容
     */
    public static CerMessageUpdateModel calculateUpdateModel(
            OldCoreCerMessage newItem,
            OldCoreCerMessage oldItem,
            OldCoreCerPerson newPerson,
            OldCoreCerPerson oldPerson
    ) {
        if (check(newPerson.getCerPersonHeadimg(), oldPerson.getCerPersonHeadimg())) {
            return new CerMessageUpdateModel(
                    UpdateAuthenticationInfoEnum.AVATAR,
                    newPerson.getCerPersonHeadimg()
            );
        }
        if (check(newItem.getCerMsgNickname(), oldItem.getCerMsgNickname())) {
            return new CerMessageUpdateModel(
                    UpdateAuthenticationInfoEnum.NAME,
                    newItem.getCerMsgNickname()
            );
        }
        if (check(newPerson.getCerPersonDetails(), oldPerson.getCerPersonDetails())) {
            return new CerMessageUpdateModel(
                    UpdateAuthenticationInfoEnum.INTRODUCE,
                    newPerson.getCerPersonDetails()
            );
        }
        if (check(newPerson.getCerPersonRange(), oldPerson.getCerPersonRange())) {
            return new CerMessageUpdateModel(
                    UpdateAuthenticationInfoEnum.BUSINESS_SCOPE,
                    newPerson.getCerPersonRange()
            );
        }
        if (check(newPerson.getCerPersonBankcard(), oldPerson.getCerPersonBankcard())) {
            return new CerMessageUpdateModel(
                    UpdateAuthenticationInfoEnum.BANK_CARD,
                    newPerson.getCerPersonBankcard()
            );
        }
        if (check(newPerson.getCerPersonAddress(), oldPerson.getCerPersonAddress())) {
            return new CerMessageUpdateModel(
                    UpdateAuthenticationInfoEnum.SHOP_ADDRESS,
                    newPerson.getCerPersonAddress()
            );
        }
        return null;
    }

    /**
     * 计算认证信息的修改
     *
     * @param newItem    旧的认证信息
     * @param oldItem    新的认证信息
     * @param newCompany 旧的认证信息
     * @param oldCompany 新的认证信息
     * @return 修改的内容
     */
    public static CerMessageUpdateModel calculateUpdateModel(
            OldCoreCerMessage newItem,
            OldCoreCerMessage oldItem,
            OldCoreCerCompany newCompany,
            OldCoreCerCompany oldCompany
    ) {
        if (check(newCompany.getCerCompanyImg(), oldCompany.getCerCompanyImg())) {
            return new CerMessageUpdateModel(
                    UpdateAuthenticationInfoEnum.AVATAR,
                    newCompany.getCerCompanyImg()
            );
        }
        if (check(newItem.getCerMsgNickname(), oldItem.getCerMsgNickname())) {
            return new CerMessageUpdateModel(
                    UpdateAuthenticationInfoEnum.NAME,
                    newItem.getCerMsgNickname()
            );
        }
        if (check(newCompany.getCerCompanyDetails(), oldCompany.getCerCompanyDetails())) {
            return new CerMessageUpdateModel(
                    UpdateAuthenticationInfoEnum.INTRODUCE,
                    newCompany.getCerCompanyDetails()
            );
        }
        if (check(newCompany.getCerCompanyOther(), oldCompany.getCerCompanyOther())) {
            return new CerMessageUpdateModel(
                    UpdateAuthenticationInfoEnum.SCENE,
                    newCompany.getCerCompanyOther()
            );
        }
        if (check(newCompany.getCerCompanyProduct(), oldCompany.getCerCompanyProduct())) {
            return new CerMessageUpdateModel(
                    UpdateAuthenticationInfoEnum.PRODUCT,
                    newCompany.getCerCompanyProduct()
            );
        }
        if (check(newCompany.getCerCompanyPremises(), oldCompany.getCerCompanyPremises())) {
            return new CerMessageUpdateModel(
                    UpdateAuthenticationInfoEnum.BUSINESS_SCOPE,
                    newCompany.getCerCompanyPremises()
            );
        }
        if (check(newCompany.getCerCompanyBankcard(), oldCompany.getCerCompanyBankcard())) {
            return new CerMessageUpdateModel(
                    UpdateAuthenticationInfoEnum.BANK_CARD,
                    newCompany.getCerCompanyBankcard()
            );
        }
        if (check(newCompany.getCerCompanyAddress(), oldCompany.getCerCompanyAddress())) {
            return new CerMessageUpdateModel(
                    UpdateAuthenticationInfoEnum.SHOP_ADDRESS,
                    newCompany.getCerCompanyAddress()
            );
        }
        return null;
    }

    /**
     * 计算认证信息的修改
     *
     * @param newContent 旧的认证信息
     * @param oldContent 新的认证信息
     * @return 修改的内容
     */
    private static boolean check(String newContent, String oldContent) {
        return !StringUtils.equals(newContent, oldContent);
    }

    public interface RunCerPersonInfo {
        /**
         * 审核中
         *
         * @param trigger              日志信息
         * @param newOldCoreCerMessage 新的认证信息
         * @param newOldCoreCerPerson  新的认证人信息
         */
        void run(
                SyncTrigger trigger,
                OldCoreCerMessage newOldCoreCerMessage,
                OldCoreCerPerson newOldCoreCerPerson
        );
    }

    public interface RunCerCompanyInfo {
        /**
         * 审核中
         *
         * @param trigger              日志信息
         * @param newOldCoreCerMessage 新的认证信息
         * @param oldCoreCerCompany    新的认证人信息
         */
        void run(
                SyncTrigger trigger,
                OldCoreCerMessage newOldCoreCerMessage,
                OldCoreCerCompany oldCoreCerCompany
        );
    }

}
